package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.core.CardAccountBoundDao;
import com.tbit.uqbike.client.pojo.newEntity.CardAccountBound;
import com.tbit.uqbike.client.service.CardAccountBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: chen
 * @Description:
 * @Date: 创建于 16:05 2023/1/3
 */
@Service
public class CardAccountBoundServiceImpl implements CardAccountBoundService {

    @Autowired
    private CardAccountBoundDao cardAccountBoundDao;

    @Override
    public CardAccountBound getByAccountId(Integer accountId, Integer brandId, Integer cardType) {
        Map<String, Object> map = new HashMap<>();
        map.put("brandId", brandId);
        map.put("cardType", cardType);
        map.put("accountId", accountId);
        return cardAccountBoundDao.getByAccountId(map);
    }

    @Override
    public List<Integer> getAccountId(Integer accountId, Integer brandId, Integer cardType) {
        /**查询是否存在区域骑行卡互通*/
        List<Integer> accountIds = new ArrayList<>();
        accountIds.add(accountId);
        CardAccountBound cardAccountBound = getByAccountId(accountId, brandId,
                cardType);
        if (cardAccountBound != null) {
            Arrays.asList(cardAccountBound.getAccountIds().split(","));
            List<Integer> idList = Arrays.stream(cardAccountBound.getAccountIds().split(",")).map(Integer::parseInt).collect(
                    Collectors.toList());
            accountIds.addAll(idList);
        }
        return accountIds;
    }
}
